/*#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
  int g_val=0;
int main(int argc, char* argv[], char* envp[])
{
 // printf("hello linux!!\n");
//  fork();
//  while(1)
//  {
//    printf("I am a process...PID:%d,PPID:%d\n",getpid(),getppid());
//    sleep(1);
//  }
//
 /* printf("I am running ...\n");
  pid_t ret=fork();
  if(ret==0)
  {
    while(1)
    {
      printf("I am a child process pid:%d\n",getpid());
      sleep(1);
    }
  }
  else if(ret>0)
  {
    while(1)
    {
      printf("I am a parent process pid:%d\n",getpid());
      sleep(1);
    }
  }*/ 
/*  printf("I am running ...\n");
  pid_t id=fork();
  if(id==0)
  {
    int count=5;
    while(count--)
    {
      printf("I am child...PID:%d, PPID:%d, count:%d\n", getpid(), getppid(), count);
			sleep(1);
    }
    printf("child quit....\n");
    exit(1);
  }
  else if(id > 0){ //father
		while(1){
			printf("I am father...PID:%d, PPID:%d\n", getpid(), getppid());
			sleep(1);
		}
	}
	else{ //fork error
	}*/ 
  
 /* for(int i=0;i<argc;i++)
  {
    printf("argv[%d]:%s\n",i,argv[i]);
  }
  int i=0;
  while(envp[i])
  {
    printf("envp[%d]:%s\n",i,envp[i]);
    i++;
  }*/
 /* pid_t id =fork();
  if(id==0)
  {
    g_val=200;
    printf("child:PID:%d,PPID:%d,g_val:%d, &g_val:%p\n",getpid(),getppid(),g_val,&g_val);
  }

  else if(id>0)
  {
    sleep(5);

    printf("father:PID:%d,PPID:%d,g_val:%d, &g_val:%p\n",getpid(),getppid(),g_val,&g_val);
  }

  return 0;
}*/

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
int main()
{
 /*fork之后，父子进程代码共享*/
  printf("Before:PID:%d\n",getpid());
  pid_t id = fork();
  if(id==-1)
  {
    printf("fail...\n");
  }
  printf("After: PID:%d,return value %d\n", getpid(),id);
  return 0;
}
